import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import myAxios from '@/request.js'

export const useLoginStore = defineStore('loginstore', () => {
  const loginUser = ref({
    id: '',
    userAccount: '',
    userName: '',
    userAvatar: '',
    userProfile: '',
    userRole: '',
    editTime: '',
    createTime: '',
    updateTime: '',
  })
  const fetchUserInfo = async () => {
    return await myAxios.request({
      url: '/api/user/getcurrentuser',
      method: 'get',
    })
  }

  const setLoginuser = (param) => {
    loginUser.value = param
  }

  const userLogout = () => {
    loginUser.value = {
      id: '',
      userAccount: '',
      userName: '',
      userAvatar: '',
      userProfile: '',
      userRole: '',
      editTime: '',
      createTime: '',
      updateTime: '',
    }
  }

  return {
    loginUser,
    fetchUserInfo,
    setLoginuser,
    userLogout,
  }
})
